<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>简介</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="book.bc.html">« BC Math</a></li>
      <li style="float: right;"><a href="bc.setup.html">安装/配置 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.bc.html">BC Math</a></li>
    <li>简介</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="intro.bc" class="preface">
  <h1 class="title">简介</h1>
  <p class="para">
    对于任意精度的数学， 如果有足够多的内存，PHP 提供的 BCMath 支持用字符串的形式表示任意大小和精度的数字，最大尺寸为
   <code class="literal">2147483647</code>（即 <code class="literal">0x7FFFFFFF</code>）。
  </p>
  <p class="para">
   有效（即格式良好）的 BCMath 数字是匹配正则表达式
   <code class="literal">/^[+-]?[0-9]*(\.[0-9]*)?$/</code> 的字符串。
  </p>
  <div class="caution"><strong class="caution">警告</strong>
   <p class="para">
    BCMath 函数想要操作的是 <span class="type">string</span>，如果传入了 <span class="type">float</span> 可能无法达到想要的效果，
    因为 PHP 会将 <span class="type">float</span> 的值转换为 <span class="type">string</span>。
    也就意味着 <span class="type">string</span> 可能会带科学计数法符号（BCMath 并不支持），
    另外在 PHP 8.0.0 之前，小数点分隔符也不支持本地化（BCMath 只能识别英文句号小数点）。
   </p>
   <div class="informalexample">
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$num1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;(string)&nbsp;0&nbsp;=&gt;&nbsp;'0'<br /></span><span style="color: #0000BB">$num2&nbsp;</span><span style="color: #007700">=&nbsp;-</span><span style="color: #0000BB">0.000005</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;(string)&nbsp;-0.000005&nbsp;=&gt;&nbsp;'-5.05E-6'<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">bcadd</span><span style="color: #007700">(</span><span style="color: #0000BB">$num1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;=&gt;&nbsp;'0.000000'<br /><br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_NUMERIC</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;使用逗号小数点<br /></span><span style="color: #0000BB">$num2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1.2</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;(string)&nbsp;1.2&nbsp;=&gt;&nbsp;'1,2'<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">bcsub</span><span style="color: #007700">(</span><span style="color: #0000BB">$num1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;=&gt;&nbsp;'0.0'<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>
 </div></div></div></body></html>